package com.kevin.ymqquan.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kevin.ymqquan.R;
import com.kevin.ymqquan.activity.MyClubActivity;
import com.kevin.ymqquan.bean.ClubListData;
import com.kevin.ymqquan.cache.ImageLoader;

public class MyClubListAdapter extends BaseAdapter {

	private ImageLoader mImageLoader;
	private List<ClubListData> myClubList;
	private LayoutInflater lf;

	public MyClubListAdapter(Activity mContext,
			List<ClubListData> myClubListData) {
		super();
		this.myClubList = myClubListData;
		mImageLoader = new ImageLoader(mContext);
		this.lf = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return myClubList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		MyClubHolder holder = null;
		holder = new MyClubHolder();

		// 自定义视图
		if (convertView == null) {

			convertView = lf.inflate(R.layout.list_club_item, parent, false);
			holder.tv_club_item_name = (TextView) convertView
					.findViewById(R.id.tv_club_item_name);
			holder.tv_club_item_owner = (TextView) convertView
					.findViewById(R.id.tv_club_item_owner);
			holder.tv_club_item_membercount = (TextView) convertView
					.findViewById(R.id.tv_club_item_membercount);
			holder.iv_club_item_logo = (ImageView) convertView
					.findViewById(R.id.iv_logo_item_logo);

			convertView.setTag(holder);
		} else {
			holder = (MyClubHolder) convertView.getTag();
		}

		holder.tv_club_item_name
				.setText(myClubList.get(position).getClubName());
		holder.tv_club_item_membercount.setText(myClubList.get(position)
				.getClubMemberCount());
		holder.tv_club_item_owner.setText(myClubList.get(position)
				.getClubOwner());

		// Log.i("kevinlog", clubList.get(position).getClubLogoUrl());
		mImageLoader.DisplayImage(myClubList.get(position).getClubLogoUrl(),
				holder.iv_club_item_logo, false);
		return convertView;
	}

	/**
	 * 自定义控件集合
	 */
	public static class MyClubHolder {
		// 名称
		public TextView tv_club_item_name;
		// 所有人
		public TextView tv_club_item_owner;
		// 会员人数
		public TextView tv_club_item_membercount;
		// logo
		public ImageView iv_club_item_logo;
	}
}
